package util;

import game.Constants;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.StringTokenizer;


public class ConfigReader {
	 public static void importConfigFile(String path)  {
			
		    
		 	
		 try {
		      BufferedReader br = new BufferedReader(new FileReader(path));
		      String line,key,value = null,tmp;
		      HashMap<String, String> hm = new HashMap<String, String>();
		 
		      while ((line=br.readLine())!=null) {
		    	  StringTokenizer tokens = new StringTokenizer(line);
				  key = tokens.nextToken();
		          while( tokens.hasMoreTokens()){
		        	  tmp = tokens.nextToken();
		        	  if( tmp.equalsIgnoreCase("="))
		        		  continue;
		        	  value = tmp;
		          }
		        	
		          hm.put(key,value);
		     
		      }
		       if( hm.containsKey((Constants.STRING_AGENT_MOBILITY_MODE)))
		    	  Constants.AGENT_MOBILITY_MODE =  Integer.parseInt( hm.get(Constants.STRING_AGENT_MOBILITY_MODE));
		      if( hm.containsKey((Constants.STRING_ENCOUNTER_SCHEDULE_TYPE)))
		    	  Constants.ENCOUNTER_SCHEDULE_TYPE =  Integer.parseInt( hm.get(Constants.STRING_ENCOUNTER_SCHEDULE_TYPE) );
		      if( hm.containsKey((Constants.STRING_ENVIRONMENT_TOPOLOGY)))
		    	  Constants.ENVIRONMENT_TOPOLOGY =  hm.get(Constants.STRING_ENVIRONMENT_TOPOLOGY) ;
		      if( hm.containsKey((Constants.STRING_GAME_ID)))
		    	  Constants.GAME_ID =  Integer.parseInt( hm.get(Constants.STRING_GAME_ID) );
		      if( hm.containsKey((Constants.STRING_MARKET_TRANSITION_PROB)))
		    	  Constants.MARKET_TRANSITION_PROB =  Integer.parseInt( hm.get(Constants.STRING_MARKET_TRANSITION_PROB) );
		      if( hm.containsKey((Constants.STRING_MESH_GENERATION_TYPE)))
		    	  Constants.MESH_GENERATION_TYPE =  Integer.parseInt( hm.get(Constants.STRING_MESH_GENERATION_TYPE) );
		      if( hm.containsKey((Constants.STRING_NUM_OF_AGENTS)))
		    	  Constants.NUM_OF_AGENTS =  Integer.parseInt( hm.get(Constants.STRING_NUM_OF_AGENTS) );
		      if( hm.containsKey((Constants.STRING_NUM_OF_ITERATION)))
		    	  Constants.NUM_OF_ITERATION =  Integer.parseInt( hm.get(Constants.STRING_NUM_OF_ITERATION) );
		      if( hm.containsKey((Constants.STRING_NUM_OF_TWO_AGENT_ENCNT)))
		    	  Constants.NUM_OF_TWO_AGENT_ENCNT =  Integer.parseInt( hm.get(Constants.STRING_NUM_OF_TWO_AGENT_ENCNT) );
		      if( hm.containsKey((Constants.STRING_NUMBER_OF_SELECTED_AGENTS_TO_BE_MOVED)))
		    	  Constants.NUMBER_OF_SELECTED_AGENTS_TO_BE_MOVED = Integer.parseInt( hm.get(Constants.STRING_NUMBER_OF_SELECTED_AGENTS_TO_BE_MOVED) );
		      if( hm.containsKey((Constants.STRING_STABILITY_CRITERIA)))
		    	  Constants.STABILITY_CRITERIA = Float.parseFloat( hm.get(Constants.STRING_STABILITY_CRITERIA));
		      if( hm.containsKey((Constants.STRING_STRATEGY_DISTR_TYPE)))
		    	  Constants.STRATEGY_DISTR_TYPE =  Integer.parseInt( hm.get(Constants.STRING_STRATEGY_DISTR_TYPE) );
		      if( hm.containsKey((Constants.STRING_SUCCESS_RATIO_FOR_AGENTS_NOT_BE_MOVED)))
		    	  Constants.SUCCESS_RATIO_FOR_AGENTS_NOT_BE_MOVED =  Double.parseDouble( hm.get(Constants.STRING_SUCCESS_RATIO_FOR_AGENTS_NOT_BE_MOVED) );
		      if( hm.containsKey((Constants.STRING_AVALUE)))
		    	  Constants.AVALUE =  Double.parseDouble( hm.get(Constants.STRING_AVALUE) );
		      if( hm.containsKey((Constants.STRING_BVALUE)))
		    	  Constants.BVALUE =  Double.parseDouble( hm.get(Constants.STRING_BVALUE) );
		      if( hm.containsKey((Constants.STRING_K1VALUE)))
		    	  Constants.K1VALUE =  Double.parseDouble( hm.get(Constants.STRING_K1VALUE) );
		      if( hm.containsKey((Constants.STRING_K2VALUE)))
		    	  Constants.K2VALUE =  Double.parseDouble( hm.get(Constants.STRING_K2VALUE) );
		      if( hm.containsKey((Constants.STRING_DIVERSITY_DISTR_TYPE)))
		    	  Constants.DIVERSITY_DISTR_TYPE =  Integer.parseInt( hm.get(Constants.STRING_DIVERSITY_DISTR_TYPE) );
		      if( hm.containsKey((Constants.STRING_TOPOLOGY_FILE_NAME)))
		    	  Constants.TOPOLOGY_FILE_NAME =   hm.get(Constants.STRING_TOPOLOGY_FILE_NAME) ;
		      if( hm.containsKey(Constants.STRING_STRATEGY_UPDATE))
		    	  Constants.STRATEGY_UPDATE = Integer.parseInt(  hm.get(Constants.STRING_STRATEGY_UPDATE) );
		      if( hm.containsKey(Constants.STRING_MOBILITY))
		    	  Constants.MOBILITY = Integer.parseInt(  hm.get(Constants.STRING_MOBILITY) );
		           
		 }
		 catch(Exception ex){
			 System.err.println("Error while reading the config file");
			 ex.printStackTrace();
		 }
		}
}
